package week_01.recursion.Iterative;

public class Iterative_f {
    //输入区间边界，计算两个的函数值，一正一负，就让x相加除二，的出来的函数值为正就与负数的x值在二分，为负就与整的x值二分
    //f(x)=Math.pow(x,2)-0.2*x-5.75
    public Iterative_f(double l, double r) {
        eqution(r);
        eqution(l);
        while ((r - l) > 0.000000001) {
            if (eqution(l) < 0) {
                l = (l + r) / 2;
            } else if (eqution(r) > 0) {
                r = (l + r) / 2;
            }
//            else if (eqution(l) > 0) {
//                l = (l + r) / 2;
//            } else if (eqution(r) < 0) {
//                r = (l + r) / 2;
//            }

        }
        System.out.println("通过迭代法计算出的左边界:" +
                l+"    右边界:"+r);
        System.out.println("通过迭代法计算出的左边界的值:" +
                eqution(l)+"    右边界的值:"+eqution(r));
    }

    double eqution(double x) {
        x = x * x - 0.2 * x - 5.75;
        return x;
    }
}
